from pms.common.views import PostFormula
from project.models import ProjectDocument
from project.utils.document import document_view
from project.utils.permission import assert_project_permissions


class API(PostFormula):

    def handle(self, req):
        doc_id = req['id']
        doc = ProjectDocument.objects.get(id=doc_id)
        assert_project_permissions(doc.pid_id, self.user.id, [2])
        view = document_view(doc)
        doc.delete()
        return self.success_respond(view)
